package com.lanqiaofinal11;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author `RKC`
 * @date 2022/6/17 11:03
 */
public class F蓝肽子序列 {

    private static final int N = 1010, P = 13331;
    private static List<Long> ls1 = new ArrayList<>(N), ls2 = new ArrayList<>(N);
    private static int[][] f = new int[N][N];
    private static String s1, s2;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        s1 = next(); s2 = next();
        //使用双指针将两个字符串的蓝肽序列串找出来，然后将序列串通过字符串哈希的方式得到一个整数放在List中，对整个List进行一次LCS的操作
        build(s1, ls1);
        build(s2, ls2);
        for (int i = 1; i <= ls1.size(); i++) {
            for (int j = 1; j <= ls2.size(); j++) {
                if (ls1.get(i - 1).equals(ls2.get(j - 1))) f[i][j] = Math.max(f[i][j], f[i - 1][j - 1] + 1);
                else f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]);
            }
        }
        writer.println(f[ls1.size()][ls2.size()]);
        writer.flush();
    }

    private static void build(String s, List<Long> ls) {
        int n = s.length();
        //双指针分割蓝肽序列串
        for (int i = 0; i < n;) {
            int j = i + 1;
            while (j < n && (s.charAt(j) >= 'a' && s.charAt(j) <= 'z')) j++;
            String sub = s.substring(i, j);
            //字符串哈希
            long h = getHash(sub);
            ls.add(h);
            i = j;
        }
    }

    private static long getHash(String s) {
        long res = 0;
        for (int i = 0; i < s.length(); i++) {
            res += s.charAt(i) - 'a' + 1;
            res *= P;
        }
        return res;
    }

    private static String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }
}
